//
//  ST_SomeOneDailyHeader.swift
//  btvideo
//
//  Created by mac on 2020/7/23.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit

class ST_SomeOneDailyHeader: UIView {
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(cover_root_view)
        cover_root_view.snp.makeConstraints { (make) in
            make.height.width.equalTo(88)
            make.left.equalToSuperview().offset(15)
            make.top.equalToSuperview().offset(15)
        }
        
        cover_root_view.addSubview(cover_image_view)
        cover_image_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 20, left: 20, bottom: 20, right: 20))
        }
        
        self.addSubview(content_label)
        content_label.snp.makeConstraints { (make) in
            make.top.equalTo(cover_root_view).offset(8)
            make.left.equalTo(cover_root_view.snp.right).offset(47)
            make.height.equalTo(22)
        }
        
        self.addSubview(pushBtn)
        pushBtn.snp.remakeConstraints { (make) in
            make.height.equalTo(40)
            make.width.equalTo(200)
            make.left.equalTo(cover_root_view.snp.right).offset(20)
            make.bottom.equalTo(cover_root_view).offset(-8)
        }
        
        let line = UIView()
        self.addSubview(line)
        line.backgroundColor = UIColor.init(hex: 0xF5F8FA)
        line.snp.remakeConstraints { (make) in
            make.height.equalTo(1)
            make.left.right.equalToSuperview()
            make.top.equalTo(pushBtn.snp.bottom).offset(28)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
//    MARK: - Bind Model
    var model:ST_DailBaseModel?{
        didSet{
            
            guard let m = model else { return  }
            
            cover_image_view.pin_setImage(from: m.image.url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            
            titleLabel.text = m.name
            
            let contentStr = NSMutableAttributedString.init(string: m.publishNum.st_number_description())
            
            contentStr.addAttributes([NSAttributedString.Key.foregroundColor:UIColor.init(hex: 0x333333)!,NSAttributedString.Key.font:UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.semibold)], range: NSRange.init(location: 0, length: contentStr.length))
            
            let contentUnitStr = NSMutableAttributedString.init(string: "条日常")
            
            contentUnitStr.addAttributes([NSAttributedString.Key.foregroundColor:UIColor.init(hex: 0xACB4C0)!,NSAttributedString.Key.baselineOffset:1,NSAttributedString.Key.font:UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)], range: NSRange.init(location: 0, length: contentUnitStr.length))
            
            contentStr.append(contentUnitStr)
            
            let lookStr = "   " + m.lookNum.st_number_description()
            let contentLookStr = NSMutableAttributedString.init(string: lookStr)
            
            contentLookStr.addAttributes([NSAttributedString.Key.foregroundColor:UIColor.init(hex: 0x333333)!,NSAttributedString.Key.font:UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.semibold)], range: NSRange.init(location: 0, length: contentLookStr.length))
            
            let contentLookUnitStr = NSMutableAttributedString.init(string: "人在看")
            
            contentLookUnitStr.addAttributes([NSAttributedString.Key.foregroundColor:UIColor.init(hex: 0xACB4C0)!,NSAttributedString.Key.baselineOffset:1,NSAttributedString.Key.font:UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)], range: NSRange.init(location: 0, length: contentLookUnitStr.length))
            
            contentLookStr.append(contentLookUnitStr)
            
            contentStr.append(contentLookStr)
            
            content_label.attributedText = contentStr
        }
    }
    
//    MARK: - Properties
    fileprivate lazy var cover_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        return control
    }()
    
    
    fileprivate lazy var cover_root_view:UIView = {
        let control = UIView()
        control.cornerRadius = 15
        control.backgroundColor = UIColor.init(hex: 0xF5F8FA)
        return control
    }()
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = UIColor.init(hexString: "#333333")
        control.font = UIFont.systemFont(ofSize: 24, weight: UIFont.Weight.semibold)
        return control
    }()
    
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        return control
    }()
    
    fileprivate lazy var pushBtn:UIButton = {
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setTitleForAllStates("发布日常")
        let enableImg = UIImage.init(color: UIColor.init(hex: 0xFEC207)!, size: CGSize.init(width: 1, height: 1))
        control.setBackgroundImage(enableImg, for: UIControl.State.normal)
        control.cornerRadius = 40/2.0
        control.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.semibold)
        control.addTarget(self, action: #selector(push_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
}


extension ST_SomeOneDailyHeader{
    
    @objc fileprivate func push_handle(){
        
        
        let vc = ST_EditDailyMomentController()
        
        vc.model = model
        
        self.parentViewController?.navigationController?.pushViewController(vc)
        
    }
    
}
